package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.client.enums.TriggerStrategy;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.manager.scene.service.OperateSceneInstService;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <Description> <br>
 *  使用类型
 * @author 杨国斌<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2022年3月16日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.attr.handler <br>
 */

public class LocalRegionUseTypeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Autowired
    OperateSceneInstService operateSceneInstService;
    @Override
    public void set(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        super.set(attr, inst, value, data);
        if(KiteStringUtils.equals("59", ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr())&&KiteStringUtils.equalsAny(attr.getValue(),"100001378","100002793","100003447")){
            List<KiteOfferInst> kiteOfferInsts =  querySceneInstService.listMainOfferInstsByProdInstId(data.getCustId(),inst.getInstId());
            if(KiteListUtils.isNotEmpty(kiteOfferInsts)){
                List<KiteOfferInst> additionalOfferInsts= querySceneInstService.listAdditionalOfferInstsFromOfferInst(data.getCustId(),kiteOfferInsts.get(0).getOfferInstId());
                if(KiteListUtils.isNotEmpty(additionalOfferInsts)){
                    additionalOfferInsts.stream().forEach( additional ->{
                        KiteAttr  feeYZ =additional.getAttr("200000169");
                        feeYZ.setValue("0");
                        feeYZ.setValueDesc("0");
                        feeYZ.setIsEdit("F");
                        operateSceneInstService.setAttr(data.getSceneInstId(), additional.getInstType(), additional.getInstId(), feeYZ);

                    });
                }
            }
        }
    }
}
